# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from spmi.time_sensor.time_after_05_30 import time_after_05_30
spmi_dws__dws_spmi_union_bill_dt = SparkSqlOperator(
    task_id='spmi_dws__dws_spmi_union_bill_dt',
    task_concurrency=1,
    pool_slots=2,
    master='yarn',
    name='spmi_dws__dws_spmi_union_bill_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='spmi/dws/spmi/dws_spmi_union_bill_dt/execute.sql',
    retries=0,
    pool='spmi_piece',
    driver_memory='4G',
    driver_cores=2,
    executor_cores=3,
    executor_memory='6G',
    email=['yushuo@jtexpress.com', 'yl_bigdata@yl-scm.com'],
    num_executors=30,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 80,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 120,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '2G',  # 堆外内存
          'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=3',
          'spark.sql.shuffle.partitions': 480,
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions': 100,  # 每天生成 20 个分区
              'hive.exec.max.dynamic.partitions.pernode': 100,  # 每天生成 20 个分区
              },
    yarn_queue='pro',
    execution_timeout=timedelta(hours=1),
)

spmi_dws__dws_spmi_union_bill_dt <<  time_after_05_30
